#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2010 - BidiX@BidiX.info
#
#
'''
    article - extend page for an article (or element)
    
    Description :
        an article (or element) is a single object to display. An admin can also edit, delete or modify
 
     Usage :
     
'''
from page import Page

from bidix.db import Article
from bidix.html import ustr


class ArticlePage(Page):
    '''
    classdocs
    '''


    def __init__(self):
        '''Constructor'''

    def initialize_page(self):
        '''Subclass should override'''
        if self.action == 'edit':
            self.with_html_editor=True
        self.name = self.match.groupdict()['name']
        self.article = Article.get_by_name(self.name)     

    def format_menu(self):
        '''Subcall should override
        return: String'''
        menu = """<a href="/a/%s?action=edit">Modifier</a>"""%self.name
        return menu
    
    def format_main_for_display(self):
        '''Subcall should override
        return: String'''
        if self.action == 'display':
            main = """<h1>%s</h1>\n"""%self.article.title
            main += self.article.text
            main += """\n<hr>\n%s"""%str(self.article.tags)            
        return main
    
    def format_main_for_edit(self):
        main = """
<div><input class="text" name="title" size="50" value=%(title)s></div>
<div><textarea id="tinymce" name="text">
%(text)s
</textarea></div>
""" % {'title': ustr(self.article.title), 'text': ustr(self.article.text)}
        return main
    
   